<template>
    <div class="wrapper">
        <vue-particles
                color="#409EFF"
                :particleOpacity="0.7"
                :particlesNumber="80"
                shapeType="circle"
                :particleSize="4"
                linesColor="#409EFF"
                :linesWidth="1"
                :lineLinked="true"
                :lineOpacity="0.4"
                :linesDistance="150"
                :moveSpeed="3"
                :hoverEffect="true"
                hoverMode="grab"
                :clickEffect="true"
                clickMode="push"
        ></vue-particles>
        <el-card class="box-card">
            <div class="title"><b>Reset</b></div>
            <el-form :model="userForm" :rules="rules" ref="ruleForm">
                <el-form-item prop="userName" style="margin: 15px 8px">
                    <el-input size="medium" v-model="userForm.userName" prefix-icon="el-icon-user-solid" placeholder="请输入用户名">
                    </el-input>
                </el-form-item>
                <el-form-item prop="email" style="margin: 15px 8px">
                    <el-input size="medium" v-model="userForm.email" prefix-icon="el-icon-message" placeholder="请输入邮箱">
                    </el-input>
                </el-form-item>
                <el-form-item prop="password" style="margin: 15px 8px">
                    <el-input size="medium" type="password" show-password v-model="userForm.password" prefix-icon="el-icon-lock" placeholder="请输入密码">
                    </el-input>
                </el-form-item>
                <el-form-item prop="password" style="margin: 15px 8px">
                    <el-input size="medium" type="password" show-password v-model="userForm.confirmPassword" prefix-icon="el-icon-lock" placeholder="请确认密码">
                    </el-input>
                </el-form-item>
                <el-form-item style="margin: 26px 8px; text-align: right">
                    <el-button type="primary" size="small" style="width: 75px;" autocomplete="off" @click="$router.push('/login')">返回</el-button>
                    <el-button type="warning" size="small" style="width: 75px;" autocomplete="off" @click="retrive">重设</el-button>
                </el-form-item>
            </el-form>
        </el-card>
    </div>
</template>

<script>
    export default {
        name: "Retrive",
        data () {
            return {
                userForm: {},
                rules: {
                    userName: [
                        { required: true, message: '请输入用户名', trigger: 'blur' },
                        { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
                    ],
                    email: [
                        { required: true, message: '请输入邮箱', trigger: 'blur' },
                        { min: 5, max: 55, message: '长度在 5 到 55 个字符', trigger: 'blur' }
                    ],
                    password: [
                        { required: true, message: '请输入密码', trigger: 'blur' },
                        { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
                    ],
                    confirmPassword: [
                        { required: true, message: '请确认密码', trigger: 'blur' },
                        { min: 3, max: 20, message: '长度在 3 到 20 个字符', trigger: 'blur' }
                    ]
                }
            }
        },
        methods: {
            retrive () {
                this.$refs['ruleForm'].validate((valid) => {
                    if (valid) {
                        if (this.userForm.password !== this.userForm.confirmPassword) {
                            this.$message.error('两次密码输入不一致!')
                        }
                        this.request.post('/user/retrive', this.userForm).then(res => {
                            if (res.code === '200') {
                                this.$message.success('密码重设成功!')
                                this.$router.push('/login')
                            } else {
                                this.$message.error(res.message)
                            }
                        })
                    } else {
                        return false
                    }
                })
            }
        }
    }
</script>

<style scoped>
    #particles-js {
        width: 100%;
        height: calc(100% - 100px);
        position: absolute;
    }
    .wrapper {
        width: 100%;
        height: 100vh;
        background-image: linear-gradient(-180deg, #1a1454 0%, #0e81a5 100%);
        overflow: hidden;
    }
    .box-card {
        width: 360px;
        height: 380px;
        margin: 150px auto;
        background-color: rgba(0, 0, 0, 0.3) !important;
        color: #999999;
        border-radius: 12px;
        background-color: #fff;
    }
    div.title {
        margin-top: 10px;
        margin-bottom: 30px;
        font-family: Broadway,serif;
        font-size: 48px;
        text-align: center;
    }
</style>